package com.nutricia.biz.convertor;

import com.nutricia.common.api.info.SystemRoleInfo;
import com.nutricia.core.model.domain.SystemRoleDO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 系统角色对象转换器
 *
 * @author: huangsheng
 * @date: 2017/10/20
 */
public class SystemRoleConvertor {

   /**
    * 将 systemRoleDO 转换为 SystemRoleInfo
    *
    * @author: huangsheng
    * @date: 2017/10/24 上午10:48
    */
    public static SystemRoleInfo convertToSystemRoleInfo(final SystemRoleDO systemRoleDO) {
        if (null == systemRoleDO) {
            return null;
        }
        SystemRoleInfo systemRoleInfo = new SystemRoleInfo();
        systemRoleInfo.setId(systemRoleDO.getId());
        systemRoleInfo.setRoleCode(systemRoleDO.getRoleCode());
        systemRoleInfo.setRoleName(systemRoleDO.getRoleName());
        return systemRoleInfo;
    }

    /**
     * 将SystemUsers转换为SystemUserDOs
     *
     * @author: huangsheng
     * @date: 2017/10/20 下午2:00
     */
    public static List<SystemRoleInfo> convertToSystemRoleInfos(final List<SystemRoleDO> systemRoleDOS) {
        List<SystemRoleInfo> systemRoleInfos = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(systemRoleDOS)) {
            systemRoleDOS.forEach(systemRoleDO -> {
                systemRoleInfos.add(SystemRoleConvertor.convertToSystemRoleInfo(systemRoleDO));
            });
            return systemRoleInfos;
        }
        return Collections.emptyList();
    }

}
